package me.sealer.ssm.utils;

import lombok.extern.slf4j.Slf4j;
import me.sealer.ssm.constant.ErrorCodeConstant;
import me.sealer.ssm.exception.SsmException;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

/**
 * 功能描述： $ ReflectUtil
 *
 * @author sealer
 * @email 1178884049@qq.com
 * @date 2020年01月16日 17时37分25秒
 */
@Slf4j
public class ReflectUtil {
    public static Object call(Object target, String methods, Object... args) {
        Object object;
        try {
            Method method = target.getClass().getMethod(methods, args.getClass());
            object = method.invoke(target, args);
        } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
            log.error("createUser method call error.");
            throw new SsmException(ErrorCodeConstant.SYSTEM_METHOD_REFLECT_CALL_ERROR);
        }

        return object;
    }
}
